package com.example.module_clocking.adapter

import android.graphics.Color
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.example.module_clocking.R
import com.example.module_clocking.databinding.ItemClockListBinding
import com.example.module_clocking.model.ClockListEntity

class ClockingAdapter (
):RecyclerView.Adapter<ClockingAdapter.ClockingViewHolder>(){
    private val list= mutableListOf<ClockListEntity>()

    fun setData(data:List<ClockListEntity>){
        list.clear()
        list.addAll(data)
        notifyDataSetChanged()
    }
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ClockingViewHolder {
        val binding=ItemClockListBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return ClockingViewHolder(binding)
    }

    override fun getItemCount(): Int {
        return list.size
    }

    override fun onBindViewHolder(holder: ClockingViewHolder, position: Int) {
        val binding=DataBindingUtil.getBinding<ItemClockListBinding>(holder.itemView)?:return
        binding.clockingData.text=list[position].morningCheckIn
        binding.clockingTimeText.text=list[position].morningCheckIn+" - "+list[position].afternoonCheckIn
        binding.clockingDz.text=list[position].location
        binding.clockingZt.text=list[position].status
        if (list[position].status=="正常"){
            binding.clockingZt.setTextColor(Color.GREEN)
            binding.clockingZt.setBackgroundResource(R.drawable.shape_type_clock)
        }else if(list[position].status=="缺勤"){
            binding.clockingZt.setTextColor(Color.RED)
            binding.clockingZt.setBackgroundResource(R.drawable.shape_type_clock01)
        }else if(list[position].status=="迟到"){
            binding.clockingZt.setTextColor(Color.YELLOW)
            binding.clockingZt.setBackgroundResource(R.drawable.shape_type_clock02)
        }else if(list[position].status=="早退"){
            binding.clockingZt.setTextColor(Color.BLUE)
            binding.clockingZt.setBackgroundResource(R.drawable.shape_type_clock03)
        }


    }
    class ClockingViewHolder(item:ItemClockListBinding) : RecyclerView.ViewHolder(item.root)

}